<div class="span3" id="backuplocation-add-block">
	<h4 class="title"><?php echo t('page', 'Add Backup Location'); ?></h4>
	<div class="squiggly-border"></div>
	<div class="row-fluid">
		<div class="span12 add_backuplocation_form_info hide" id="auth_backuplocation_success_info">
			<div class="alert alter-block alert-success">
	<!--			<button type="button" class="close" data-dismiss="alert">&times;</button>-->
				<h4>Success</h4>
				<div class="content">Successfully Authenticated, Please wait while we download your cPanel backuplocation data.</div>
			</div>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span12 add_backuplocation_form_info hide" id="add_backuplocation_success_info">
			<div class="alert alter-block alert-success">
	<!--			<button type="button" class="close" data-dismiss="alert">&times;</button>-->
				<h4>Success</h4>
				<div class="content">New New backuplocation has been added!</div>
			</div>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span12 add_backuplocation_form_info hide" id="add_backuplocation_error_info">
			<div class="alert alter-block alert-error">
	<!--			<button type="button" class="close" data-dismiss="alert">&times;</button>-->
				<h4>Error</h4>
				<div class="content"></div>
			</div>
		</div>
	</div>
	
	<?php $form = $this->beginWidget('CActiveForm', array(
		'id' => 'backuplocation-add-form',
		'enableClientValidation' => true,
		'clientOptions' => array(
			'validateOnSubmit' => true,
		),
	)); ?>
	
		<div class="row-fluid">
			<?php echo $form->textField($backupLocationsAddForm, 'name', array('placeholder' => $backupLocationsAddForm->getFieldLabel('name'), 'class' => 'fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->dropDownList($backupLocationsAddForm, 'protocol', $backupLocationsAddForm->listProtocols(), array('class' => 'fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->textField($backupLocationsAddForm, 'server', array('placeholder' => $backupLocationsAddForm->getFieldLabel('server'), 'class' => 'fields unhomedir_fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->textField($backupLocationsAddForm, 'username', array('placeholder' => $backupLocationsAddForm->getFieldLabel('username'), 'class' => 'fields unhomedir_fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->passwordField($backupLocationsAddForm, 'password', array('placeholder' => $backupLocationsAddForm->getFieldLabel('password'), 'class' => 'fields unhomedir_fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->textField($backupLocationsAddForm, 'port', array('placeholder' => $backupLocationsAddForm->getFieldLabel('port'), 'class' => 'fields unhomedir_fields')); ?>
		</div>
		<div class="row-fluid">
			<?php echo $form->textField($backupLocationsAddForm, 'directory', array('placeholder' => $backupLocationsAddForm->getFieldLabel('directory'), 'class' => 'fields unhomedir_fields')); ?>
		</div>
		<div class="row-fluid buttons">
			<?php echo CHtml::ajaxSubmitButton(
				t('buttons', 'Add Backup Location'), 
				app()->createUrl('backup/location/index'),
				array(
					'type' => 'post',
					'beforeSend' => 'function(){
						//$("#add_backuplocation_submit").button("loading");
					}',
					'success' => 'function(ret){
						$("#add_backuplocation_submit").button("reset");
						if(ret["result"]){
							$("#add_backuplocation_success_info").blink({
								"beforeCall": function(){
									var tr = $("<tr class=\"new-line\" />");
									tr.append( $("<td class=\"hide id_backup_locations\" />").html(ret["detail"]["id_backup_locations"]) );
									//tr.append( $("<td />").html('.json_encode(CHtml::checkBox("backuplocations[checked][]", false, array("class" => "backuplocations_check"))).') );
									tr.append( $("<td class=\"name\" />").html(ret["detail"]["name"]) );
									tr.append( $("<td class=\"protocol\" />").html(ret["detail"]["protocol"]) );
									tr.append( $("<td class=\"server\" />").html(ret["detail"]["server"]) );
									tr.append( $("<td class=\"username\" />").html(ret["detail"]["username"]) );
									tr.append( $("<td class=\"port\" />").html(ret["detail"]["port"]) );
									tr.append( $("<td class=\"directory\" />").html(ret["detail"]["directory"]) );
									tr.append( $("<td />").html('.json_encode(BackupLocations::model()->renderListActionButtons()).') );
									
									$("#backuplocations_grid table").prepend(tr);
									
									$(".new-line").removeClass("new-line");
									$("form#backuplocation-add-form .fields").val("");
								}
							});
						}else{
							$("#add_backuplocation_error_info").blink({
								"beforeCall": function(){
									$("#add_backuplocation_error_info .content").html("");
									$.each(ret["errors"], function(attrName, error){
										$(error).each(function(k, e){
											var p = $("<p />").addClass("text-error").append(attrName+": "+e);
											$("#add_backuplocation_error_info .content").append(p);
										});
									});
								}
							});
						}
					}',
					'dataType' => 'json'
				),
				array(
					'id' => 'add_backuplocation_submit',
					'type' => 'button', 
					'class' => 'btn btn-small btn-primary',
					'data-loading-text' => t('buttons', 'Saving...')
				)
			); ?>
		</div>
	<?php $this->endWidget(); ?>
	<script>
		$(document).ready(function(){
			$('#backuplocation-add-form .fields').val('');

			$('#BackupLocationsAddForm_protocol').change(function(){
				if($(this).val() != '<?php echo BackupLocations::PROTOCOL_HOMEDIR ?>'){
					$('#backuplocation-add-form .unhomedir_fields').show();
				}else{
					$('#backuplocation-add-form .unhomedir_fields').hide();
				}
			}).change();
		});
	</script>
</div>